<template>
  <div class="container">
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item :label="$t('position_name')" prop="rankName">
          <el-input
            v-model="form.rankName"
            :placeholder="$t('please_enter', { name: $t('position_name') })"
            :show-word-limit="true"
          />
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('form')">{{
          $t("confirm")
        }}</el-button>
        <el-button @click="cancel">{{ $t("cancel") }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title: this.$t("add_new_position"),
      open: false,
      form: {},
      rules: {
        rankName: [
          {
            required: true,
            message: this.$t("cannot_empty", {
              name: this.$t("position_name"),
            }),
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {},
  methods: {
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.open = false;
          this.$emit("handleSuccess", this.form);
        } else {
          return false;
        }
      });
    },
    cancel() {
      this.open = false;
    },

    handleAddPosition() {
      this.form = {};
      this.open = true;
    },
  },
};
</script>

<style lang="scss" scoped></style>
